export default class player extends Laya.Script {

    // 更多参数说明请访问: https://ldc2.layabox.com/doc/?nav=zh-as-2-4-0
    owner=this.owner as Laya.Sprite
    Xcha=null;
    Ycah=null;
    cha=null;
    start=false;
    constructor() { super(); }
    
    onAwake(){
        Laya.stage.on("start",this,function(){this.start=true})
        Laya.stage.on("gamerover",this,function(){this.start=false})
        Laya.stage.on("gamerover3",this,function(){this.start=false})
        
    }
    onTriggerEnter(other){
        if(other.label=="food"){
            Laya.SoundManager.playSound("res/sound/defeng.wav",1);
            this.owner.autoAnimation="Fly"
            Laya.stage.event("+")
            Laya.timer.once(1000,this,function(){this.owner.autoAnimation="Idle"})
        }
        if(other.label=="shi"){
            Laya.SoundManager.playSound("res/sound/shi.wav",1);
            this.owner.autoAnimation="Die"
            Laya.stage.event("-")
            Laya.timer.once(1000,this,function(){this.owner.autoAnimation="Idle"})
        }
    }
    onUpdate(){
        if(!this.start)return;
        this.owner.x= Laya.stage.mouseX
        this.owner.y= Laya.stage.mouseY
        if(this.owner.x<109){
            this.owner.x=109
        }
        if(this.owner.x>1805){
            this.owner.x=1805
        }
        if(this.owner.y<146){
            this.owner.y=146
        }
        if(this.owner.y>770){
            this.owner.y=770
        }
    }


}